package com.jeff.android.lab.architecture.arouter;

import android.content.Context;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.facade.service.SerializationService;
import com.jeff.utils.JSONUtil;

import java.lang.reflect.Type;

/**
 * 用于传递自定义对象
 *
 * @author: dingfeng
 * @date: 2021/1/22
 * @since: 1.0.0
 **/
@Route(path = "/jack/json")
public class JsonServiceImpl implements SerializationService {
    @Override
    public <T> T json2Object(String input, Class<T> clazz) {
        return JSONUtil.optFromJsonString(input, clazz);
    }

    @Override
    public String object2Json(Object instance) {
        return JSONUtil.optToJsonString(instance);
    }

    @Override
    public <T> T parseObject(String input, Type clazz) {
        return JSONUtil.optFromJsonString(input, clazz);
    }

    @Override
    public void init(Context context) {

    }
}
